/*
 * StuManageLog.java
 *
 * Created on __DATE__, __TIME__
 */

package com.rongjun.zheng.view;

import java.sql.Connection;

import javax.swing.JOptionPane;

import com.rongjun.zheng.dao.ManagerDao;
import com.rongjun.zheng.model.Manager;
import com.rongjun.zheng.util.DbUtil;

/**
 *
 * @author  __USER__
 */
public class StuManageLog extends javax.swing.JFrame {
	DbUtil dbUtil = new DbUtil();
	ManagerDao managerdao = new ManagerDao();

	/** Creates new form StuManageLog */
	public StuManageLog() {
		initComponents();
		this.setLocationRelativeTo(null);
		
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jLabel1 = new javax.swing.JLabel();
		jLabel2 = new javax.swing.JLabel();
		manageUserName = new javax.swing.JTextField();
		managerUserPassword = new javax.swing.JPasswordField();
		jLabel3 = new javax.swing.JLabel();
		logon = new javax.swing.JButton();
		jButton2 = new javax.swing.JButton();
		jLabel4 = new javax.swing.JLabel();
		jButton3 = new javax.swing.JButton();

		setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
		setTitle("\u5b66\u751f\u7ba1\u7406\u7cfb\u7edf");
		setResizable(false);
		addWindowListener(new java.awt.event.WindowAdapter() {

			public void windowClosing(java.awt.event.WindowEvent evt) {
				formWindowClosing(evt);
			}
		});

		jLabel1.setFont(new java.awt.Font("����", 0, 24));
		jLabel1.setIcon(new javax.swing.ImageIcon(".\\images\\student.png")); // NOI18N
		jLabel1.setText("\u5b66\u751f\u7ba1\u7406\u7cfb\u7edf");

		jLabel2.setFont(new java.awt.Font("����", 0, 14));
		jLabel2.setIcon(new javax.swing.ImageIcon(
				".\\images\\user.png")); // NOI18N
		jLabel2.setText("\u7528\u6237\u540d");


		jLabel3.setFont(new java.awt.Font("����", 0, 14));
		jLabel3.setIcon(new javax.swing.ImageIcon(".\\images\\password.png")); // NOI18N
		jLabel3.setText("\u5bc6\u7801");

		logon.setText("\u767b\u9646");
		logon.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				logonActionPerformed(evt);
			}
		});

		jButton2.setText("\u6ce8\u518c");
		jButton2.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton2ActionPerformed(evt);
			}
		});

		jLabel4.setIcon(new javax.swing.ImageIcon(".\\images\\Teacher.png")); // NOI18N

		jButton3.setText("\u91cd\u7f6e");
		jButton3.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton3ActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(
				getContentPane());
		getContentPane().setLayout(layout);
		layout
				.setHorizontalGroup(layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								javax.swing.GroupLayout.Alignment.TRAILING,
								layout
										.createSequentialGroup()
										.addGap(49, 49, 49)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																javax.swing.GroupLayout.Alignment.TRAILING,
																layout
																		.createSequentialGroup()
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addGroup(
																								layout
																										.createSequentialGroup()
																										.addGroup(
																												layout
																														.createParallelGroup(
																																javax.swing.GroupLayout.Alignment.LEADING,
																																false)
																														.addComponent(
																																jLabel3,
																																javax.swing.GroupLayout.DEFAULT_SIZE,
																																javax.swing.GroupLayout.DEFAULT_SIZE,
																																Short.MAX_VALUE)
																														.addComponent(
																																jLabel2))
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																										.addGroup(
																												layout
																														.createParallelGroup(
																																javax.swing.GroupLayout.Alignment.LEADING)
																														.addComponent(
																																manageUserName,
																																javax.swing.GroupLayout.DEFAULT_SIZE,
																																193,
																																Short.MAX_VALUE)
																														.addComponent(
																																managerUserPassword,
																																javax.swing.GroupLayout.DEFAULT_SIZE,
																																193,
																																Short.MAX_VALUE)))
																						.addGroup(
																								layout
																										.createSequentialGroup()
																										.addGap(
																												79,
																												79,
																												79)
																										.addComponent(
																												jLabel1,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												181,
																												javax.swing.GroupLayout.PREFERRED_SIZE)))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				jLabel4)
																		.addGap(
																				18,
																				18,
																				18))
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addGap(
																				51,
																				51,
																				51)
																		.addComponent(
																				logon)
																		.addGap(
																				18,
																				18,
																				18)
																		.addComponent(
																				jButton2)
																		.addGap(
																				18,
																				18,
																				18)
																		.addComponent(
																				jButton3)
																		.addContainerGap()))));
		layout
				.setVerticalGroup(layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								layout
										.createSequentialGroup()
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addComponent(jLabel4)
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addGap(
																				30,
																				30,
																				30)
																		.addComponent(
																				jLabel1,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				57,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addGroup(
																								layout
																										.createSequentialGroup()
																										.addComponent(
																												manageUserName,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												javax.swing.GroupLayout.DEFAULT_SIZE,
																												javax.swing.GroupLayout.PREFERRED_SIZE)
																										.addGap(
																												28,
																												28,
																												28)
																										.addComponent(
																												managerUserPassword,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												javax.swing.GroupLayout.DEFAULT_SIZE,
																												javax.swing.GroupLayout.PREFERRED_SIZE))
																						.addGroup(
																								layout
																										.createSequentialGroup()
																										.addComponent(
																												jLabel2,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												21,
																												javax.swing.GroupLayout.PREFERRED_SIZE)
																										.addGap(
																												28,
																												28,
																												28)
																										.addComponent(
																												jLabel3,
																												javax.swing.GroupLayout.PREFERRED_SIZE,
																												21,
																												javax.swing.GroupLayout.PREFERRED_SIZE)))
																		.addGap(
																				34,
																				34,
																				34)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								logon)
																						.addComponent(
																								jButton2)
																						.addComponent(
																								jButton3))))
										.addContainerGap(80, Short.MAX_VALUE)));

		pack();
	}// </editor-fold>
	//GEN-END:initComponents

	private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
		ManagerReginterJD managerReginterJD = new ManagerReginterJD();
		managerReginterJD.setLocationRelativeTo(null);
		managerReginterJD.setVisible(true);
	}

	private void formWindowClosing(java.awt.event.WindowEvent evt) {
		// TODO add your handling code here:
		int num = JOptionPane.showConfirmDialog(null, "�Ƿ�Ҫ�˳�");
		if (num == 0) {
			System.exit(0);
		}
	}

	private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
		this.manageUserName.setText("");
		this.managerUserPassword.setText("");
	}

	private void logonActionPerformed(java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
		String user = this.manageUserName.getText();
		String password = this.managerUserPassword.getText();
		if (user == null) {
			JOptionPane.showMessageDialog(null, "�˺Ų���Ϊ��");
		}
		if (password == null) {
			JOptionPane.showMessageDialog(null, "���벻��Ϊ��");
		}
		Connection con = null;
		Manager currentManager = null;
		try {
			con = dbUtil.getCon();
			currentManager = managerdao.login(con, user, password);
			if (currentManager != null) {
				//this.dispose();
				JOptionPane.showMessageDialog(null, "��½�ɹ�");
				new MainFrm().setVisible(true);
				this.dispose();
				
			} else {
				JOptionPane.showMessageDialog(null, "��½ʧ��");
			}

		} catch (Exception e) {
			// TODO Auto-generated catch block
			JOptionPane.showMessageDialog(null, "��½ʧ��");
			e.printStackTrace();
		}finally{
			try {
				dbUtil.close(con);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}

	}

	/**
	 * @param args the command line arguments
	 */
	public static void main(String args[]) {
		java.awt.EventQueue.invokeLater(new Runnable() {
			public void run() {
				new StuManageLog().setVisible(true);
			}
		});
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton jButton2;
	private javax.swing.JButton jButton3;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JLabel jLabel3;
	private javax.swing.JLabel jLabel4;
	private javax.swing.JButton logon;
	private javax.swing.JTextField manageUserName;
	private javax.swing.JPasswordField managerUserPassword;
	// End of variables declaration//GEN-END:variables

}